﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Win32;
using SuporeSliplampApp.Util;
using System.Windows.Media.Animation;
using SuporeSliplampApp.Properties;
using static SuporeSliplampApp.Util.Common;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// PrintSetting.xaml 的交互逻辑
    /// </summary>
    public partial class PrintSetting : Window
    {

        Common.Printinfo printinfo = new Common.Printinfo();

        public PrintSetting()
        {
            InitializeComponent();

            if (File.Exists("printinfo.json"))
            {
                string json = File.ReadAllText("printinfo.json");
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<Printinfo>(json);
                nameBox.Text = info.printname;
                adressBox.Text = info.printaddress;
                phoneBox.Text = info.printtelephone.ToString();
                logoBox.Text = info.logeimage;
            }

        }


        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void OpenPath_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "图片|*.jpg;*.jpeg;*.bmp;*.png;*.mp4"
            };
            if (openFileDialog.ShowDialog() == true)
            {
                logoBox.Text = openFileDialog.FileName;
            }
        }

        private void SaveBtn_Click(Object sender, RoutedEventArgs e)
        {
            printinfo.printname = nameBox.Text;
            printinfo.printaddress = adressBox.Text;
            printinfo.printtelephone = phoneBox.Text;
            printinfo.logeimage = logoBox.Text;

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(printinfo, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText("printinfo.json", json);

            this.Close();
        }


    }
}
